package com.example.firstprojectnew.exception;

import com.example.firstprojectnew.common.WrapMapper;
import com.example.firstprojectnew.common.Wrapper;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: lihua
 * @Date: 2025/3/14 14:18
 * @Version: v1.0.0
 * @Description: 全局异常处理
 **/
@ControllerAdvice
@RestController
@Order(2)
public class MyExceptionController {

//
//    @ExceptionHandler(value = RuntimeException.class)
//    public Wrapper retAllException(){
//        return WrapMapper.error("服务器内部出现了问题");
//    }

    @ExceptionHandler(value = NullPointerException.class)
    public Wrapper getNullPointException(Exception e){

        return WrapMapper.error("空指针异常");
    }

    @ExceptionHandler(value = LoginException.class)
    public Wrapper loginException(LoginException loginException){
        return WrapMapper.error(loginException.getMessage());
    }

}
